home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
os2
/
rsynth21.zip
/
nsynth.c
< prev
next >
Wrap
Text File
|
1995-12-19
|
32KB
|
1,067 lines
#include <config.h>
/* $Id: nsynth.c,v 1.13 1994/11/08 13:30:50 a904209 Exp a904209 $
*/
char *nsynth_id = "$Id: nsynth.c,v 1.13 1994/11/08 13:30:50 a904209 Exp a904209 $";
/* Copyright 1982 by Dennis H. Klatt
* Klatt synthesizer
* Modified version of synthesizer described in
* J. Acoust. Soc. Am., Mar. 1980. -- new voicing
* source.
*
* Edit history
* 000001 10-Mar-83 DK Initial creation.
* 000002 5-May-83 DK Fix bug in operation of parallel F1
* 000003 7-Jul-83 DK Allow parallel B1 to vary, and if ALL_PARALLEL,
* also allow B2 and B3 to vary
* 000004 26-Jul-83 DK Get rid of mulsh, use short for VAX
* 000005 24-Oct-83 DK Split off parwavtab.c, change short to int
* 000006 16-Nov-83 DK Make samrate a variable, use exp(), cos() rand()
* 000007 17-Nov-83 DK Convert to float, remove cpsw, add set outsl
* 000008 28-Nov-83 DK Add simple impulsive glottal source option
* 000009 7-Dec-83 DK Use spkrdef[7] to select impulse or natural voicing
* and update cascade F1,..,F6 at update times
* 000010 19-Dec-83 DK Add subroutine no_rad_char() to get rid of rad char
* 000011 28-Jan-84 DK Allow up to 8 formants in cascade branch F7 fixed
* at 6.5 kHz, F8 fixed at 7.5 kHz
* 000012 14-Feb-84 DK Fix bug in 'os' options so os>12 works
* 000013 17-May-84 DK Add G0 code
* 000014 12-Mar-85 DHW modify for Haskins environment
* 000015 11-Jul-87 LG modificiations for PC
* 000016 20-Apr-91 ATS Modified for SPARCSTATION
*/
#include <useconfig.h>
#include <stdio.h>
#include <math.h>
#include "proto.h"
#include "nsynth.h"
#ifndef PI
#ifndef M_PI /* <math.h> */
#define PI 3.1415927
#else /* M_PI */
#define PI M_PI
#endif /* M_PI */
#endif
#ifdef __STDC__
#define ONE 1.0F
#else
#define ONE 1.0
#endif
typedef struct
{
char *name;
float a;
float b;
float c;
float p1;
float p2;
}
resonator_t, *resonator_ptr;
/* Various global variables */
int time_count = 0;
static warnsw; /* JPI added for f0 flutter */
/* COUNTERS */
static long nper; /* Current loc in voicing period 40000 samp/s */
/* COUNTER LIMITS */
static long T0; /* Fundamental period in output samples times 4 */
static long nopen; /* Number of samples in open phase of period */
static long nmod; /* Position in period to begin noise amp. modul */
/* Variables that have to stick around for awhile, and thus locals
are not appropriate
*/
/* Incoming parameter Variables which need to be updated synchronously */
static long F0hz10; /* Voicing fund freq in Hz */
static long F0hz10org; /* Original Fundamental Freq */
static long AVdb; /* Amp of voicing in dB, 0 to 70 */
static long Kskew; /* Skewness of alternate periods,0 to 40 */
/* Various amplitude variables used in main loop */
static float amp_voice; /* AVdb converted to linear gain */
static float amp_bypas; /* AB converted to linear gain */
static float par_amp_voice; /* AVpdb converted to linear gain */
static float amp_aspir; /* AP converted to linear gain */
static float amp_frica; /* AF converted to linear gain */
static float amp_breth; /* ATURB converted to linear gain */
/* State variables of sound sources */
static long skew; /* Alternating jitter, in half-period units */
static float natglot_a; /* Makes waveshape of glottal pulse when open */
static float natglot_b; /* Makes waveshape of glottal pulse when open */
static float vwave; /* Ditto, but before multiplication by AVdb */
static float vlast; /* Previous output of voice */
static float nlast; /* Previous output of random number generator */
static float glotlast; /* Previous value of glotout */
static float decay; /* TLTdb converted to exponential time const */
static float onemd; /* in voicing one-pole low-pass filter */
static float minus_pi_t; /* func. of sample rate */
static float two_pi_t; /* func. of sample rate */
/* INTERNAL MEMORY FOR DIGITAL RESONATORS AND ANTIRESONATOR */
static resonator_t rnpp =
{"parallel nasal pole"};
static resonator_t r1p =
{"parallel 1st formant"};
static resonator_t r2p =
{"parallel 2nd formant"};
static resonator_t r3p =
{"parallel 3rd formant"};
static resonator_t r4p =
{"parallel 4th formant"};
static resonator_t r5p =
{"parallel 5th formant"};
static resonator_t r6p =
{"parallel 6th formant"};
static resonator_t r1c =
{"cascade 1st formant"};
static resonator_t r2c =
{"cascade 2nd formant"};
static resonator_t r3c =
{"cascade 3rd formant"};
static resonator_t r4c =
{"cascade 4th formant"};
static resonator_t r5c =
{"cascade 5th formant"};
static resonator_t r6c =
{"cascade 6th formant"};
static resonator_t r7c =
{"cascade 7th formant"};
static resonator_t r8c =
{"cascade 8th formant"};
static resonator_t rnpc =
{"cascade nasal pole"};
static resonator_t rnz =
{"cascade nasal zero"};
static resonator_t rgl =
{"crit-damped glot low-pass filter"};
static resonator_t rlp =
{"downsamp low-pass filter"};
static resonator_t rout =
{"output low-pass"};
/*
* Constant natglot[] controls shape of glottal pulse as a function
* of desired duration of open phase N0
* (Note that N0 is specified in terms of 40,000 samples/sec of speech)
*
* Assume voicing waveform V(t) has form: k1 t**2 - k2 t**3
*
* If the radiation characterivative, a temporal derivative
* is folded in, and we go from continuous time to discrete
* integers n: dV/dt = vwave[n]
* = sum over i=1,2,...,n of { a - (i * b) }
* = a n - b/2 n**2
*
* where the constants a and b control the detailed shape
* and amplitude of the voicing waveform over the open
* potion of the voicing cycle "nopen".
*
* Let integral of dV/dt have no net dc flow --> a = (b * nopen) / 3
*
* Let maximum of dUg(n)/dn be constant --> b = gain / (nopen * nopen)
* meaning as nopen gets bigger, V has bigger peak proportional to n
*
* Thus, to generate the table below for 40 <= nopen <= 263:
*
* natglot[nopen - 40] = 1920000 / (nopen * nopen)
*/
static const short natglot[224] =
{
1200, 1142, 1088, 1038, 991, 948, 907, 869, 833, 799,
768, 738, 710, 683, 658, 634, 612, 590, 570, 551,
533, 515, 499, 483, 468, 454, 440, 427, 415, 403,
391, 380, 370, 360, 350, 341, 332, 323, 315, 307,
300, 292, 285, 278, 272, 265, 259, 253, 247, 242,
237, 231, 226, 221, 217, 212, 208, 204, 199, 195,
192, 188, 184, 180, 177, 174, 170, 167, 164, 161,
158, 155, 153, 150, 147, 145, 142, 140, 137, 135,
133, 131, 128, 126, 124, 122, 120, 119, 117, 115,
113, 111, 110, 108, 106, 105, 103, 102, 100, 99,
97, 96, 95, 93, 92, 91, 90, 88, 87, 86,
85, 84, 83, 82, 80, 79, 78, 77, 76, 75,
75, 74, 73, 72, 71, 70, 69, 68, 68, 67,
66, 65, 64, 64, 63, 62, 61, 61, 60, 59,
59, 58, 57, 57, 56, 56, 55, 55, 54, 54,
53, 53, 52, 52, 51, 51, 50, 50, 49, 49,
48, 48, 47, 47, 46, 46, 45, 45, 44, 44,
43, 43, 42, 42, 41, 41, 41, 41, 40, 40,
39, 39, 38, 38, 38, 38, 37, 37, 36, 36,
36, 36, 35, 35, 35, 35, 34, 34, 33, 33,
33, 33, 32, 32, 32, 32, 31, 31, 31, 31,
30, 30, 30, 30, 29, 29, 29, 29, 28, 28,
28, 28, 27, 27
};
/*
* Convertion table, db to linear, 87 dB --> 32767
* 86 dB --> 29491 (1 dB down = 0.5**1/6)
* ...
* 81 dB --> 16384 (6 dB down = 0.5)
* ...
* 0 dB --> 0
*
* The just noticeable difference for a change in intensity of a vowel
* is